import path from 'path-browserify';
export default defineNuxtPlugin(async () => {
  // if (process.env.NODE_ENV === 'development') {
  const runtimeConfig = useRuntimeConfig();
  const { worker } = await import('~~/mocks/browser');

  // console.log(path.join(runtimeConfig.app.baseURL, '/mockServiceWorker.js'));
  // console.log(path.join(runtimeConfig.app.baseURL, ''));
  // console.log(path.join(runtimeConfig.app.baseURL, '/'));
  // console.log(path.join(runtimeConfig.public.apiBaseUrl, '/'));

  worker.printHandlers();
  await worker.start({
    quiet: false,
    serviceWorker: {
      url: path.join(runtimeConfig.app.baseURL, '/mockServiceWorker.js'),
      options: {
        // 拦截范围, 判断的是初始化的页面url，不是请求的apiurl
        scope: path.join(runtimeConfig.app.baseURL, '/'),
      },
    },
    // 进入拦截的请求在未匹配时的处理方式
    onUnhandledRequest: 'bypass',
    // waitUntilReady: true,
  });
  // }
});
